Sample Code - GraphObject Object

This sample code shows the use of the GraphObject Object. Modify the following sample code to fit your needs.

Private Sub Command1_Click()
On Error GoTo Command1_Click_Error

Dim crystalApplication As CRPEAuto.Application
Dim crystalReport As CRPEAuto.Report
Dim crystalSections As CRPEAuto.Sections
Dim crystalSection As CRPEAuto.Section
Dim crystalReportObjects As CRPEAuto.ReportObjects
Dim crystalGraphObject As CRPEAuto.GraphObject

Dim intSectionCount As Integer
Dim intReportObjectCount As Integer
Dim intObjectFound As Integer
Dim strTitle As String
Dim strGraphDisplayType As String

Set crystalApplication = CreateObject("Crystal.CRPE.Application")
Set crystalReport = crystalApplication.OpenReport _
    ("d:\crw\reports\craze\wwsales.rpt")

Set crystalSections = crystalReport.Sections
intObjectFound = False
intSectionCount = 1
While Not (intObjectFound) And _
intSectionCount <= crystalSections.Count

Set crystalSection = crystalSections.Item(intSectionCount)
Set crystalReportObjects = crystalSection.ReportObjects
intReportObjectCount = 1

While Not (intObjectFound) And _
intReportObjectCount <= crystalSection.ReportObjects.Count

Select Case crystalReportObjects.Item(intReportObjectCount).Kind
Case 1 'FieldObject
Case 2 'TextObject
Case 3 'LineObject
Case 4 'BoxObject
Case 5 'SubReportObject
Case 6 'OLEObject
Case 7 'GraphObject

intObjectFound = True
Set crystalGraphObject = _
         crystalReportObjects.Item(intReportObjectCount)

Case 8 'CrossTabObject
Case 9 'BLOBFieldObject
Case Else
End Select
intReportObjectCount = intReportObjectCount + 1
Wend 'bottom of while loop through report objects within section

intSectionCount = intSectionCount + 1
Wend 'bottom of while loop through sections within report

If intObjectFound Then
strTitle = crystalGraphObject.Title
Select Case crystalGraphObject.DisplayType
Case 2
strGraphDisplayType = "StackedBar"
Case 3
strGraphDisplayType = "PercentBar"
Case 4
strGraphDisplayType = "3DSideBySideBar"
Case 5
strGraphDisplayType = "3DStackedBar"
Case 6
strGraphDisplayType = "3DPercentBar"
Case Else
strGraphDisplayType = "Other or Unknown"
End Select

Debug.Print "GraphObject.Title<" + strTitle + ">"
Debug.Print "GraphObject.DisplayType<" + strGraphDisplayType + ">"

End If

Command1_Click_Exit:
Exit Sub

Command1_Click_Error:
If crystalApplication Is Nothing Then
MsgBox "Unable to CreateObject(""Crystal.CRPE.Application"")"
GoTo Command1_Click_Exit
End If
If crystalReport Is Nothing Then
MsgBox "Unable to OpenReport(""d:\crw\reports\craze\wwsales.rpt"")"
GoTo Command1_Click_Exit
End If
MsgBox "Unknown error in Command1_Click routine"
GoTo Command1_Click_Exit
End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com